/*     */ package com.newcrm.businessarchives;
/*     */ 
/*     */ import com.newcrm.exception.CaptchaException;
/*     */ import com.newcrm.util.Util;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.io.UnsupportedEncodingException;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ import org.jsoup.nodes.Element;
/*     */ import org.jsoup.select.Elements;
/*     */ 
/*     */ public class NewGuangdongSearchEngine extends SearchEngine
/*     */ {
/*  28 */   private static Logger logger = Logger.getLogger(NewGuangdongSearchEngine.class.getName());
/*     */ 
/*  30 */   private Map<String, String> params = new HashMap();
/*     */ 
/*     */   public static void main(String[] args)
/*     */     throws CaptchaException
/*     */   {
/*  37 */     NewGuangdongSearchEngine searchEngine = new NewGuangdongSearchEngine(
/*  38 */       "珠海佳力五金制品有限公司");
/*  39 */     Map items = searchEngine.getCompanyByWeb();
/*  40 */     System.out.println(items);
/*     */   }
/*     */ 
/*     */   public NewGuangdongSearchEngine(String name) {
/*  44 */     this.name = standardizedName(name);
/*     */ 
/*  46 */     this.params.put("注册号", "SN");
/*  47 */     this.params.put("名称", "CompanyName");
/*  48 */     this.params.put("类型", "CompanyType");
/*  49 */     this.params.put("法定代表人", "Header");
/*  50 */     this.params.put("注册资本", "RegisteredCapital");
/*  51 */     this.params.put("成立日期", "FoundedDate");
/*  52 */     this.params.put("住所", "Address");
/*  53 */     this.params.put("营业期限自", "OperatingPeriodStart");
/*  54 */     this.params.put("营业期限至", "OperatingPeriodEnd");
/*  55 */     this.params.put("经营范围", "BusinessScope");
/*  56 */     this.params.put("登记机关", "RegistrationAuthority");
/*  57 */     this.params.put("经营状态", "AnnualinSpectionResult");
/*     */   }
/*     */ 
/*     */   protected Map<String, Object> getCompanyByWeb()
/*     */     throws CaptchaException
/*     */   {
/*  68 */     if (!isValid(this.name)) {
/*  69 */       return null;
/*     */     }
/*     */ 
/*  73 */     String url = "";
/*     */     try {
/*  75 */       url = "http://gsxt.gdgs.gov.cn/CheckEntContext/showInfo.html?textfield=" + 
/*  76 */         URLEncoder.encode(this.name.trim(), "utf-8");
/*     */     } catch (UnsupportedEncodingException e) {
/*  78 */       url = "http://gsxt.gdgs.gov.cn/CheckEntContext/showInfo.html?textfield=" + this.name.trim();
/*     */     }
/*     */     try
/*     */     {
/*  82 */       Document doc = Jsoup.connect(url)
/*  83 */         .header("Host", "gsxt.gdgs.gov.cn")
/*  84 */         .referrer("http://gsxt.gdgs.gov.cn/").userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/*  85 */         .timeout(60000).get();
/*  86 */       Elements links = doc.select("dl[class=list] dt a");
/*  87 */       String detailUrl = null;
/*  88 */       if ((links != null) && (links.size() >= 1)) {
/*  89 */         detailUrl = links.get(0).absUrl("href");
/*     */       }
/*     */ 
/*  92 */       if ((detailUrl == null) || (detailUrl.trim().length() == 0)) {
/*  93 */         return null;
/*     */       }
/*     */ 
/*  98 */       doc = Jsoup.connect(detailUrl).header("Host", "gsxt.gdgs.gov.cn")
/*  99 */         .referrer("http://gsxt.gdgs.gov.cn/").userAgent("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB6.6; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET CLR 1.1.4322; .NET4.0C)")
/* 100 */         .timeout(10000).get();
/* 101 */       links = doc.select("div[id=jibenxinxi] th");
/* 102 */       if (links == null) {
/* 103 */         return null;
/*     */       }
/*     */ 
/* 106 */       Map info = new HashMap();
/* 107 */       for (Element item : links) {
/* 108 */         String key = item.text().trim();
/* 109 */         if (this.params.containsKey(key))
/*     */         {
/* 112 */           if (item.nextElementSibling() != null)
/*     */           {
/* 115 */             info.put((String)this.params.get(key), item.nextElementSibling().text()
/* 116 */               .trim());
/*     */           }
/*     */         }
/*     */       }
/* 119 */       info.put("OperatingPeriod", info.get("OperatingPeriodStart") + " - " + 
/* 120 */         info.get("OperatingPeriodEnd"));
/* 121 */       info.put("UpdateDate", Util.date2Str(new Date()));
/* 122 */       if (info.size() > 1)
/*     */       {
/* 124 */         saveDB(info);
/*     */       }
/*     */ 
/* 127 */       return info;
/*     */     } catch (IOException e) {
/* 129 */       logger.warn("get company from web failed", e);
/*     */     }
/* 131 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.businessarchives.NewGuangdongSearchEngine
 * JD-Core Version:    0.6.1
 */